import React, { Component } from 'react'

class Child extends Component{
    state={
        title:"标题"
    }
     componentWillReceiveProps(nextProps){
        // 最先获得父组件传来的属性，可以利用属性进行ajax或者逻辑处理
        // 把属性转化成自己的状态
         console.log("componentWillReceiveProps",nextProps);
         this.setState({
            title:nextProps.text+"派大星"
         })
     }
    render(){
        return(
            <div>{this.state.title}</div>
        )
    }
}
export default class App extends Component {
    state={
        text:"huahua"
    }
  render() {
    return (
      <div>
        {this.state.text}
        <button onClick={()=>{
            this.setState({
                text:"海绵宝宝"
            })
        }}>click</button>
        <Child text={this.state.text}></Child>
      </div>
    )
  }
}
